home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / pyshared / launchpadlib / wadl-to-refhtml.xsl < prev   
Extensible Markup Language  |  2009-07-13  |  36KB  |  954 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.   wadl-to-refhtml.xsl
  4.  
  5.   Generate HTML documentation for a webservice described in a WADL file.
  6.   This is tailored to WADL generated by Launchpad's web service.
  7.  
  8.   Based on wadl_documentaion.xsl from Mark Nottingham <mnot@yahoo-inc.com>
  9.   that can be found at http://www.mnot.net/webdesc/
  10.   Copyright (c) 2006-2007 Yahoo! Inc.
  11.   Copyright (c) 2008 Canonical Ltd.
  12.  
  13.   This work is licensed under the Creative Commons Attribution-ShareAlike 2.5
  14.   License. To view a copy of this license, visit
  15.     http://creativecommons.org/licenses/by-sa/2.5/
  16.   or send a letter to
  17.     Creative Commons
  18.     543 Howard Street, 5th Floor
  19.     San Francisco, California, 94105, USA
  20. -->
  21.  
  22. <xsl:stylesheet
  23.  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
  24.  xmlns:wadl="http://research.sun.com/wadl/2006/10"
  25.  xmlns:html="http://www.w3.org/1999/xhtml"
  26.  xmlns="http://www.w3.org/1999/xhtml"
  27.  exclude-result-prefixes="xsl wadl html"
  28. >
  29.     <xsl:output
  30.         method="xml"
  31.         encoding="UTF-8"
  32.         indent="yes"
  33.         doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
  34.         doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
  35.     />
  36.  
  37.  
  38.     <!-- Allow using key('id', 'people') to identify unique elements, since
  39.     the document doesn't have a parsed DTD.
  40.     -->
  41.     <xsl:key name="id" match="*[@id]" use="@id"/>
  42.  
  43.     <!-- Embedded stylesheet. -->
  44.     <xsl:template name="css-stylesheet">
  45.         <style type="text/css">
  46.             body {
  47.                 font-family: sans-serif;
  48.                 font-size: 0.85em;
  49.                 margin: 2em 8em;
  50.             }
  51.             .methods {
  52.                 background-color: #eef;
  53.                 padding: 1em;
  54.             }
  55.             .method {
  56.                 padding-left: 4em;
  57.             }
  58.             h1 {
  59.                 font-size: 2.5em;
  60.             }
  61.             h2 {
  62.                 border-bottom: 1px solid black;
  63.                 margin-top: 1em;
  64.                 margin-bottom: 0.5em;
  65.                 font-size: 2em;
  66.                }
  67.             h3 {
  68.                 color: orange;
  69.                 font-size: 1.75em;
  70.                 margin-top: 1.25em;
  71.                 margin-bottom: 0em;
  72.             }
  73.             h4 {
  74.                 font-size: 1.50em;
  75.                 margin: 0em;
  76.                 padding: 0em;
  77.                 border-bottom: 2px solid white;
  78.             }
  79.             h5 {
  80.                 font-size: 1.25em;
  81.                 margin-left: -3em;
  82.             }
  83.             h6 {
  84.                 font-size: 1.1em;
  85.                 color: #99a;
  86.                 margin: 0.5em 0em 0.25em 0em;
  87.             }
  88.             dd {
  89.                 margin-left: 1em;
  90.             }
  91.             tt, code {
  92.                 font-size: 1.2em;
  93.             }
  94.             table {
  95.                 margin-bottom: 0.5em;
  96.             }
  97.             th {
  98.                 text-align: left;
  99.                 font-weight: normal;
  100.                 color: black;
  101.                 border-bottom: 1px solid black;
  102.                 padding: 3px 6px;
  103.             }
  104.             td {
  105.                 padding: 3px 6px;
  106.                 vertical-align: top;
  107.                 background-color: f6f6ff;
  108.                 font-size: 0.85em;
  109.             }
  110.             td p {
  111.                 margin: 0px;
  112.             }
  113.             ul {
  114.                 padding-left: 1.75em;
  115.             }
  116.             p + ul, p + ol, p + dl {
  117.                 margin-top: 0em;
  118.             }
  119.             label {
  120.                 font-weight: bold;
  121.             }
  122.             .optional {
  123.                 font-weight: normal;
  124.                 opacity: 0.75;
  125.             }
  126.         </style>
  127.     </xsl:template>
  128.  
  129.     <!-- Contains the base URL for the webservice without a trailing
  130.          slash.  -->
  131.     <xsl:variable name="base">
  132.         <xsl:variable name="uri" select="//wadl:resources/@base"/>
  133.         <xsl:choose>
  134.             <xsl:when
  135.                 test="substring($uri, string-length($uri) , 1) = '/'">
  136.                 <xsl:value-of
  137.                     select="substring($uri, 1, string-length($uri) - 1)"/>
  138.             </xsl:when>
  139.             <xsl:otherwise>
  140.                 <xsl:value-of select="$uri"/>
  141.             </xsl:otherwise>
  142.         </xsl:choose>
  143.     </xsl:variable>
  144.  
  145.     <!-- Generate the URL to the top-level collection. -->
  146.     <xsl:template name="resource-uri-doc">
  147.         <xsl:param name="url"><xsl:value-of
  148.                 select="$base"/>/<xsl:value-of select="@id"/></xsl:param>
  149.         <p><label>URL:</label>
  150.             <code><xsl:copy-of select="$url" /></code></p>
  151.     </xsl:template>
  152.  
  153.     <xsl:template name="entry-uri-doc">
  154.         <xsl:call-template name="resource-uri-doc">
  155.             <xsl:with-param name="url">
  156.                 <xsl:choose>
  157.                     <xsl:when test="@id = 'has_milestones'
  158.                                     or @id = 'bug_target'
  159.                                     or @id = 'has_bugs'">
  160.                         <em>depends on the underlying entry</em>
  161.                     </xsl:when>
  162.                     <xsl:otherwise>
  163.                         <xsl:call-template name="find-entry-uri"/>
  164.                      </xsl:otherwise>
  165.                  </xsl:choose>
  166.             </xsl:with-param>
  167.         </xsl:call-template>
  168.     </xsl:template>
  169.  
  170.     <xsl:template name="find-entry-uri">
  171.         <xsl:value-of select="$base"/>
  172.         <xsl:choose>
  173.             <xsl:when test="@id = 'archive'">
  174.                 <xsl:text>/</xsl:text>
  175.                 <var><distribution></var>
  176.                 <xsl:text>/+archive/</xsl:text>
  177.                 <var><name></var>
  178.             </xsl:when>
  179.             <xsl:when test="@id = 'archive_permission'">
  180.                 <xsl:text>/</xsl:text>
  181.                 <var><archive.distribution></var>
  182.                 <xsl:text>/+archive/</xsl:text>
  183.                 <var><archive.name></var>
  184.                 <xsl:text>/+</xsl:text>
  185.                 <xsl:text>name</xsl:text>
  186.                 <xsl:text>/</xsl:text>
  187.                 <xsl:text>person.name</xsl:text>
  188.                 <xsl:text>.</xsl:text>
  189.                 <xsl:text>[component or source package].name</xsl:text>
  190.             </xsl:when>
  191.             <xsl:when test="@id = 'branch'">
  192.                 <xsl:text>/~</xsl:text>
  193.                 <var><author.name></var>
  194.                 <xsl:text>/</xsl:text>
  195.                 <var><project.name></var>
  196.                 <xsl:text>/</xsl:text>
  197.                 <var><name></var>
  198.             </xsl:when>
  199.             <xsl:when test="@id = 'branch_merge_proposal'">
  200.                 <xsl:text>/~</xsl:text>
  201.                 <var><author.name></var>
  202.                 <xsl:text>/</xsl:text>
  203.                 <var><project.name></var>
  204.                 <xsl:text>/</xsl:text>
  205.                 <var><branch.name></var>
  206.                 <xsl:text>/+merge/</xsl:text>
  207.                 <var><id></var>
  208.             </xsl:when>
  209.             <xsl:when test="@id = 'bug'">
  210.                 <xsl:text>/bugs/</xsl:text><var><id></var>
  211.             </xsl:when>
  212.             <xsl:when test="@id = 'bug_attachment'">
  213.                 <xsl:text>/bugs/</xsl:text>
  214.                 <var><bug.id></var>
  215.                 <xsl:text>/attachments/</xsl:text>
  216.                 <var><id></var>
  217.             </xsl:when>
  218.             <xsl:when test="@id = 'bug_subscription'">
  219.                 <xsl:text>/bugs/</xsl:text>
  220.                 <var><bug.id></var>
  221.                 <xsl:text>/subscriptions/</xsl:text>
  222.                 <var><subscriber.name></var>
  223.             </xsl:when>
  224.             <xsl:when test="@id = 'bug_task'">
  225.                 <xsl:text>/</xsl:text>
  226.                 <var><target.name></var>
  227.                 <xsl:text>/+bug/</xsl:text>
  228.                 <var ><bug.id></var>
  229.             </xsl:when>
  230.             <xsl:when test="@id = 'bug_watch'">
  231.                 <xsl:text>/bugs/</xsl:text>
  232.                 <var><bug.id></var>
  233.                 <xsl:text>/watch/</xsl:text>
  234.                 <var><id></var>
  235.             </xsl:when>
  236.             <xsl:when test="@id = 'bug_tracker'">
  237.                 <xsl:text>/bugs/bugtrackers/</xsl:text>
  238.                 <var><name></var>
  239.             </xsl:when>
  240.             <xsl:when test="@id = 'cve'">
  241.                 <xsl:text>/bugs/cve/</xsl:text>
  242.                 <var><sequence></var>
  243.             </xsl:when>
  244.             <xsl:when test="@id = 'distribution_source_package'">
  245.                 <xsl:text>/</xsl:text>
  246.                 <var><distribution.name></var>
  247.                 <xsl:text>/+source/</xsl:text>
  248.                 <var><name></var>
  249.             </xsl:when>
  250.             <xsl:when test="@id = 'distro_series'">
  251.                 <xsl:text>/</xsl:text>
  252.                 <var><distribution.name></var>
  253.                 <xsl:text>/</xsl:text>
  254.                 <var><name></var>
  255.             </xsl:when>
  256.             <xsl:when test="@id = 'email_address'">
  257.                 <xsl:text>/</xsl:text>
  258.                 <var><person.name></var>
  259.                 <xsl:text>/+email/</xsl:text>
  260.                 <var><email></var>
  261.             </xsl:when>
  262.             <xsl:when test="@id = 'h_w_device'">
  263.                 <xsl:text>/+hwdb/+device/</xsl:text>
  264.                 <var><id></var>
  265.             </xsl:when>
  266.             <xsl:when test="@id = 'h_w_driver'">
  267.                 <xsl:text>/+hwdb/+driver/</xsl:text>
  268.                 <var><id></var>
  269.             </xsl:when>
  270.             <xsl:when test="@id = 'h_w_submission'">
  271.                 <xsl:text>/+hwdb/+submission/</xsl:text>
  272.                 <var><submission-key></var>
  273.             </xsl:when>
  274.             <xsl:when test="@id = 'h_w_submission_device'">
  275.                 <xsl:text>/+hwdb/+submissiondevice/</xsl:text>
  276.                 <var><id></var>
  277.             </xsl:when>
  278.             <xsl:when test="@id = 'h_w_vendor_i_d'">
  279.                 <xsl:text>/+hwdb/+hwvendorid/</xsl:text>
  280.                 <var><id></var>
  281.             </xsl:when>
  282.             <xsl:when test="@id = 'jabber_id'">
  283.                 <xsl:text>/</xsl:text>
  284.                 <var><person.name></var>
  285.                 <xsl:text>/+jabberid/</xsl:text>
  286.                 <var><id></var>
  287.             </xsl:when>
  288.             <xsl:when test="@id = 'irc_id'">
  289.                 <xsl:text>/</xsl:text>
  290.                 <var><person.name></var>
  291.                 <xsl:text>/+ircnick/</xsl:text>
  292.                 <var><id></var>
  293.             </xsl:when>
  294.             <xsl:when test="@id = 'language'">
  295.                 <xsl:text>/+languages/</xsl:text>
  296.                 <var><code></var>
  297.             </xsl:when>
  298.             <xsl:when test="@id = 'message'">
  299.                 <xsl:text>/</xsl:text>
  300.                 <var><target.name></var>
  301.                 <xsl:text>/+bug/</xsl:text>
  302.                 <var><bug.id></var>
  303.                 <xsl:text>/comments/</xsl:text>
  304.                 <var><index></var>
  305.             </xsl:when>
  306.             <xsl:when test="@id = 'milestone'">
  307.                 <xsl:text>/</xsl:text>
  308.                 <var><target.name></var>
  309.                 <xsl:text>/+milestone/</xsl:text>
  310.                 <var><name></var>
  311.             </xsl:when>
  312.             <xsl:when test="   @id = 'distribution'
  313.                             or @id = 'pillar'
  314.                             or @id = 'product'
  315.                             or @id = 'project'
  316.                             or @id = 'project_group'">
  317.                 <xsl:text>/</xsl:text>
  318.                 <var><name></var>
  319.             </xsl:when>
  320.             <xsl:when test="@id = 'team' or @id = 'person'">
  321.                 <xsl:text>/~</xsl:text>
  322.                 <var><name></var>
  323.             </xsl:when>
  324.             <xsl:when test="@id = 'product_release'">
  325.                 <xsl:text>/</xsl:text>
  326.                 <var><product.name></var>
  327.                 <xsl:text>/</xsl:text>
  328.                 <var><product_series.name></var>
  329.                 <xsl:text>/</xsl:text>
  330.                 <var><name></var>
  331.             </xsl:when>
  332.             <xsl:when test="@id = 'product_series'">
  333.                 <xsl:text>/</xsl:text>
  334.                 <var><product.name></var>
  335.                 <xsl:text>/</xsl:text>
  336.                 <var><name></var>
  337.             </xsl:when>
  338.             <xsl:when test="@id = 'project_release'">
  339.                 <xsl:text>/</xsl:text>
  340.                 <var><project.name></var>
  341.                 <xsl:text>/</xsl:text>
  342.                 <var><project_series.name></var>
  343.                 <xsl:text>/</xsl:text>
  344.                 <var><release.version></var>
  345.             </xsl:when>
  346.             <xsl:when test="@id = 'project_release_file'">
  347.                 <xsl:text>/</xsl:text>
  348.                 <var><project.name></var>
  349.                 <xsl:text>/</xsl:text>
  350.                 <var><project_series.name></var>
  351.                 <xsl:text>/</xsl:text>
  352.                 <var><release.version></var>
  353.                 <xsl:text>/+file/</xsl:text>
  354.                 <var><hosted_file.filename></var>
  355.             </xsl:when>
  356.             <xsl:when test="@id = 'project_series'">
  357.                 <xsl:text>/</xsl:text>
  358.                 <var><project.name></var>
  359.                 <xsl:text>/</xsl:text>
  360.                 <var><name></var>
  361.             </xsl:when>
  362.             <xsl:when test="@id = 'source_package_publishing_history'">
  363.                 <xsl:text>/</xsl:text>
  364.                 <var><distribution></var>
  365.                 <xsl:text>/+archive/</xsl:text>
  366.                 <var><name></var>
  367.                 <xsl:text>/+sourcepub/</xsl:text>
  368.                 <var><id></var>
  369.             </xsl:when>
  370.             <xsl:when test="@id = 'team_membership'">
  371.                 <xsl:text>/</xsl:text>
  372.                 <var><team.name></var>
  373.                 <xsl:text>/+member/</xsl:text>
  374.                 <var><member.name></var>
  375.             </xsl:when>
  376.             <xsl:when test="@id = 'wiki_name'">
  377.                 <xsl:text>/</xsl:text>
  378.                 <var><person.name></var>
  379.                 <xsl:text>/+wikiname/</xsl:text>
  380.                 <var><id></var>
  381.             </xsl:when>
  382.             <xsl:when test="@id = 'commercial_subscription'">
  383.                 <xsl:text>/+commercialsubscription/</xsl:text>
  384.                 <var><commercial_subscription.id></var>
  385.             </xsl:when>
  386.             <xsl:otherwise>
  387.                 <xsl:message>Unknown entry URL:
  388.                     <xsl:value-of select="@id" />
  389.                 </xsl:message>
  390.             </xsl:otherwise>
  391.         </xsl:choose>
  392.     </xsl:template>
  393.     <!-- We start here. -->
  394.     <xsl:template match="/wadl:application">
  395.         <xsl:variable name="title">
  396.             <xsl:choose>
  397.                 <xsl:when test="wadl:doc[@title]">
  398.                     <xsl:value-of select="wadl:doc[@title][1]/@title"/>
  399.                 </xsl:when>
  400.                 <xsl:otherwise>Launchpad Web Service API</xsl:otherwise>
  401.             </xsl:choose>
  402.         </xsl:variable>
  403.         <html>
  404.             <head>
  405.                 <title><xsl:value-of select="$title" /></title>
  406.                 <xsl:call-template name="css-stylesheet"/>
  407.             </head>
  408.             <body>
  409.                 <h1><xsl:value-of select="$title" /></h1>
  410.                 <xsl:apply-templates select="wadl:doc"/>
  411.  
  412.                 <xsl:call-template name="top-level-collections" />
  413.                 <xsl:call-template name="entry-types" />
  414.             </body>
  415.         </html>
  416.     </xsl:template>
  417.  
  418.     <!-- Top level collections container -->
  419.     <xsl:template name="top-level-collections">
  420.         <div id="top-level-collections">
  421.             <h2>Top-level collections</h2>
  422.  
  423.             <!--
  424.                 Top-level collections are found in the WADL by
  425.                 looking at the representation of the service-root resource
  426.                 and processing all the resource-type linked from it.
  427.             -->
  428.             <xsl:for-each
  429.                 select="key('id', 'service-root-json')/wadl:param/wadl:link">
  430.                 <xsl:sort select="../@name" />
  431.                 <xsl:variable name="collection_id"
  432.                     select="substring-after(@resource_type, '#')" />
  433.  
  434.                 <xsl:apply-templates
  435.                     select="key('id', $collection_id)"
  436.                     mode="top-level-collections" />
  437.             </xsl:for-each>
  438.         </div>
  439.     </xsl:template>
  440.  
  441.     <xsl:template name="find-root-object-uri">
  442.         <xsl:value-of select="$base"/>
  443.         <xsl:choose>
  444.             <xsl:when test="@id = 'hwdb'">
  445.                 <xsl:text>/+hwdb</xsl:text>
  446.             </xsl:when>
  447.             <xsl:otherwise>
  448.                 <xsl:text>/</xsl:text><xsl:value-of select="@id" />
  449.             </xsl:otherwise>
  450.         </xsl:choose>
  451.     </xsl:template>
  452.  
  453.     <!-- Documentation for one top-level-collection -->
  454.     <xsl:template match="wadl:resource_type" mode="top-level-collections">
  455.         <div id="{@id}" class="top-level-collection">
  456.             <h3><xsl:call-template name="get-title-or-id"/></h3>
  457.             <xsl:apply-templates select="wadl:doc"/>
  458.  
  459.             <xsl:call-template name="resource-uri-doc">
  460.                 <xsl:with-param name="url">
  461.                     <!-- The default URL schema used for root objects of
  462.                          Launchpad's webservice is
  463.  
  464.                              [urlbase]/[root-object-name]
  465.  
  466.                          e.g,
  467.  
  468.                              https://api.launchpad.net/beta/bugs
  469.  
  470.                          while the HWDB application root's URL is
  471.  
  472.                             https://api.launchpad.net/beta/+hwdb
  473.  
  474.                          In other words, the URL for the HWDB application
  475.                          root needs to be mangled in a form similar to
  476.                          that used for non-root objects in the template
  477.                          "find-entry-uri".
  478.                     -->
  479.  
  480.                     <xsl:call-template name="find-root-object-uri"/>
  481.                 </xsl:with-param>
  482.             </xsl:call-template>
  483.  
  484.             <!-- All top-level collections supports a GET without arguments
  485.             iterating over all the resources.
  486.             The type of the resource is found by looking at the href attribute
  487.             of the default representation. Link is in the form
  488.             <resource>-page.
  489.              -->
  490.             <dl class="methods standard">
  491.                 <h4>Standard method</h4>
  492.                 <xsl:variable name="default_get"
  493.                     select="wadl:method[not(wadl:request)][1]" />
  494.                 <xsl:variable name="resource_type"
  495.                     select="substring-after(
  496.                         substring-before(
  497.                             $default_get//wadl:representation[
  498.                                 not(@mediaType)]/@href, '-page'),
  499.                         '#')" />
  500.                 <dt>GET</dt>
  501.                 <dd>Response contains a <a href="#{$resource_type}"
  502.                         ><xsl:call-template name="get-title-or-id">
  503.                             <xsl:with-param name="element"
  504.                                 select="key('id', $resource_type)" />
  505.                          </xsl:call-template></a>
  506.                 collection.</dd>
  507.             </dl>
  508.  
  509.             <xsl:call-template name="custom-GETs" />
  510.             <xsl:call-template name="custom-POSTs" />
  511.         </div>
  512.     </xsl:template>
  513.  
  514.     <!-- Documentation for the standard methods on an entry -->
  515.     <xsl:template name="standard-methods">
  516.         <dl id="{@id}-standard-methods" class="methods standard">
  517.             <h4>Standard methods</h4>
  518.  
  519.             <!-- Standard methods are the ones without a ws.op param. -->
  520.             <xsl:apply-templates
  521.                 select="wadl:method[not(.//wadl:param[@name = 'ws.op'])]"
  522.                 mode="standard-method">
  523.                 <xsl:sort select="@name"/>
  524.             </xsl:apply-templates>
  525.         </dl>
  526.     </xsl:template>
  527.  
  528.     <!-- Documentation for the standard GET on an entry -->
  529.     <xsl:template match="wadl:method[@name='GET']" mode="standard-method">
  530.         <dt><xsl:value-of select="@name" /></dt>
  531.         <dd>Response contains the default
  532.             <xsl:call-template name="representation-type" /> representation
  533.             for this entry.
  534.         </dd>
  535.     </xsl:template>
  536.  
  537.     <!-- Documentation for the standard PUT on an entry -->
  538.     <xsl:template match="wadl:method[@name='PUT']" mode="standard-method">
  539.         <dt><xsl:value-of select="@name" /></dt>
  540.         <dd>Entity body should contain a representation encoded using
  541.             <xsl:call-template name="representation-type" /> of the entry.
  542.             All fields of the default representation should be included. Only
  543.             fields marked as writeable in the default representation should be
  544.             modified.
  545.         </dd>
  546.     </xsl:template>
  547.  
  548.     <!-- Documentation for the standard PATCH on an entry -->
  549.     <xsl:template match="wadl:method[@name='PATCH']" mode="standard-method">
  550.         <dt><xsl:value-of select="@name" /></dt>
  551.         <dd>Entity body should contain a represention encoded using
  552.             <xsl:call-template name="representation-type"/> of the entry
  553.             fields to update. Any fields of the default representation marked
  554.             as writeable can be included.
  555.         </dd>
  556.     </xsl:template>
  557.  
  558.     <!-- Documentation for the custom GET operations of the resource type -->
  559.     <xsl:template name="custom-GETs">
  560.         <xsl:variable name="operations" select="wadl:method[
  561.                 @name = 'GET'][.//wadl:param[@name = 'ws.op']]" />
  562.  
  563.         <xsl:if test="$operations">
  564.             <div id="{@id}-custom-GETs" class="methods GETs">
  565.                 <h4>Custom GET methods</h4>
  566.  
  567.                 <xsl:apply-templates select="$operations">
  568.                     <xsl:sort select=".//wadl:param[@name='ws.op']/@fixed"/>
  569.                 </xsl:apply-templates>
  570.             </div>
  571.         </xsl:if>
  572.     </xsl:template>
  573.  
  574.     <!-- Documentation for the custom POST operations of the resource type -->
  575.     <xsl:template name="custom-POSTs">
  576.         <xsl:variable name="operations" select="wadl:method[
  577.             @name = 'POST'][.//wadl:param[@name = 'ws.op']]" />
  578.  
  579.         <xsl:if test="$operations">
  580.             <div id="{@id}-custom-POSTs" class="methods POSTs">
  581.                 <h4>Custom POST methods</h4>
  582.  
  583.                 <xsl:apply-templates select="$operations">
  584.                     <xsl:sort select=".//wadl:param[@name='ws.op']/@fixed"/>
  585.                 </xsl:apply-templates>
  586.             </div>
  587.         </xsl:if>
  588.     </xsl:template>
  589.  
  590.     <!-- Container for all the entry types documentation -->
  591.     <xsl:template name="entry-types">
  592.         <h2 id="entry-types">Entry types</h2>
  593.  
  594.         <!-- Process all the resource_types, except the service-root ones,
  595.           the type describing collections of that type,
  596.           or any other ones, linked from within the service root.
  597.           -->
  598.         <xsl:for-each select="wadl:resource_type[
  599.                 @id != 'service-root'
  600.                 and @id != 'HostedFile'
  601.                 and not(contains(@id, 'page-resource'))
  602.             ]">
  603.             <xsl:sort select="@id" />
  604.             <xsl:variable name="id" select="./@id"/>
  605.             <xsl:variable name="top_level_collections"
  606.                 select="key('id', 'service-root-json')//@resource_type[
  607.                     substring-after(., '#') = $id]" />
  608.             <xsl:if test="not($top_level_collections[contains(., $id)])">
  609.                 <xsl:apply-templates select="." mode="entry-types" />
  610.             </xsl:if>
  611.         </xsl:for-each>
  612.     </xsl:template>
  613.  
  614.     <!-- Documentation for one entry-type -->
  615.     <xsl:template match="wadl:resource_type" mode="entry-types">
  616.         <h3 id="{@id}"><xsl:call-template name="get-title-or-id"/></h3>
  617.         <xsl:apply-templates select="wadl:doc"/>
  618.  
  619.         <xsl:call-template name="entry-uri-doc"/>
  620.  
  621.         <xsl:call-template name="default-representation" />
  622.         <xsl:call-template name="standard-methods" />
  623.         <xsl:call-template name="custom-GETs" />
  624.         <xsl:call-template name="custom-POSTs" />
  625.     </xsl:template>
  626.  
  627.     <!-- Documentation of the default representation for an entry -->
  628.     <xsl:template name="default-representation">
  629.         <xsl:variable name="default_get" select="wadl:method[
  630.             @name = 'GET' and not(wadl:request)]" />
  631.         <xsl:variable name="representation" select="key(
  632.                 'id', substring-after(
  633.                     $default_get/wadl:response/wadl:representation[
  634.                         not(@mediaType)]/@href, '#'))"/>
  635.  
  636.         <div class="representation">
  637.             <h4>Default representation
  638.                 (<xsl:value-of select="$representation/@mediaType"/>)</h4>
  639.  
  640.             <table>
  641.                 <th>Key</th>
  642.                 <th>Value</th>
  643.                 <th>Description</th>
  644.                 <xsl:apply-templates select="$representation/wadl:param"
  645.                     mode="representation">
  646.                     <xsl:sort select="@name"/>
  647.                 </xsl:apply-templates>
  648.             </table>
  649.         </div>
  650.     </xsl:template>
  651.  
  652.     <!-- Output the cell containing the field name.
  653.  
  654.     current() should be a wadl:param.
  655.     -->
  656.     <xsl:template name="param-name">
  657.         <td>
  658.             <p><strong><xsl:value-of select="@name"/></strong></p>
  659.         </td>
  660.     </xsl:template>
  661.  
  662.     <!-- Output a table cell containing the parameter description.
  663.  
  664.     current() should a wadl:param.
  665.     -->
  666.     <xsl:template name="param-description">
  667.         <td>
  668.             <xsl:apply-templates select="wadl:doc"/>
  669.             <xsl:if test="wadl:option[wadl:doc]">
  670.                 <dl>
  671.                     <xsl:apply-templates
  672.                         select="wadl:option" mode="option-doc"/>
  673.                 </dl>
  674.             </xsl:if>
  675.         </td>
  676.     </xsl:template>
  677.  
  678.     <!-- Output information about the parameter value.
  679.  
  680.     current() should be a wadl:param.
  681.     -->
  682.     <xsl:template name="param-value">
  683.         <xsl:if test="wadl:option">
  684.             <p><em>One of:</em></p>
  685.             <ul>
  686.                 <xsl:apply-templates select="wadl:option"/>
  687.             </ul>
  688.         </xsl:if>
  689.         <xsl:apply-templates select="wadl:link[@resource_type]"/>
  690.         <xsl:if test="@default">
  691.             <p>
  692.                 Default:
  693.                 <var><xsl:value-of select="@default"/></var>
  694.             </p>
  695.         </xsl:if>
  696.         <xsl:if test="@fixed">
  697.             <p>
  698.                 Fixed:
  699.                 <var><xsl:value-of select="@fixed"/></var>
  700.             </p>
  701.         </xsl:if>
  702.     </xsl:template>
  703.  
  704.     <!-- Output row describing one field in the default representation -->
  705.     <xsl:template match="wadl:param" mode="representation">
  706.         <xsl:variable name="resource_type"
  707.             select="substring-before(../@id, '-')" />
  708.         <xsl:variable name="patch_representation_id"
  709.             ><xsl:value-of select="$resource_type"/>-diff</xsl:variable>
  710.         <xsl:variable name="patch_representation"
  711.             select="key('id', $patch_representation_id)"/>
  712.         <tr>
  713.             <xsl:call-template name="param-name"/>
  714.             <td>
  715.                 <p>
  716.                     <xsl:choose>
  717.                         <xsl:when test="$patch_representation/wadl:param[@name
  718.                             = current()/@name]">
  719.                             <small>(writeable)</small>
  720.                         </xsl:when>
  721.                         <xsl:otherwise>
  722.                             <small>(read-only)</small>
  723.                         </xsl:otherwise>
  724.                     </xsl:choose>
  725.                 </p>
  726.                 <xsl:call-template name="param-value" />
  727.             </td>
  728.             <xsl:call-template name="param-description" />
  729.         </tr>
  730.     </xsl:template>
  731.  
  732.     <!-- Output the description of a link type in param listing -->
  733.     <xsl:template match="wadl:link[
  734.         @resource_type and ../@name != 'self_link']">
  735.         <xsl:variable name="resource_type"
  736.             select="substring-after(@resource_type, '#')"/>
  737.         <xsl:choose>
  738.             <xsl:when test="contains($resource_type, 'page-resource')">
  739.                 Link to a <a href="#{substring-before($resource_type, '-')}"
  740.                     ><xsl:value-of
  741.                         select="substring-before($resource_type, '-')"
  742.                         /></a> collection.
  743.             </xsl:when>
  744.             <xsl:when test="$resource_type = 'HostedFile'">
  745.                 Link to a file resource.
  746.             </xsl:when>
  747.             <xsl:otherwise>
  748.                 Link to a <a href="#{$resource_type}"
  749.                     ><xsl:value-of select="$resource_type"/></a>.
  750.             </xsl:otherwise>
  751.         </xsl:choose>
  752.     </xsl:template>
  753.  
  754.     <!-- Documentation for a custom method -->
  755.     <xsl:template match="wadl:method[.//wadl:param[@name = 'ws.op']]">
  756.         <div class="method">
  757.             <h5 id="{@id}"><xsl:value-of
  758.                     select=".//wadl:param[@name = 'ws.op']/@fixed"/></h5>
  759.             <xsl:choose>
  760.                 <xsl:when test="wadl:doc|wadl:request|wadl:response">
  761.                     <xsl:apply-templates select="wadl:doc"/>
  762.                     <xsl:apply-templates select="wadl:request"/>
  763.                     <xsl:apply-templates select="wadl:response"/>
  764.                 </xsl:when>
  765.                 <xsl:otherwise>
  766.                     <p><em>Missing documentation.</em></p>
  767.                 </xsl:otherwise>
  768.             </xsl:choose>
  769.         </div>
  770.     </xsl:template>
  771.  
  772.     <!-- Documentation for the request parameters of a custom method -->
  773.     <xsl:template match="wadl:request">
  774.         <h6>Parameters</h6>
  775.         <table>
  776.             <tr>
  777.                 <th>Parameter</th>
  778.                 <th>Value</th>
  779.                 <th>Description</th>
  780.            </tr>
  781.             <xsl:apply-templates
  782.                 select=".//wadl:param[@style='query'][@fixed]"/>
  783.             <xsl:apply-templates
  784.                 select=".//wadl:param[@style='query'][not(@fixed)]">
  785.                 <xsl:sort select="@name" />
  786.             </xsl:apply-templates>
  787.         </table>
  788.     </xsl:template>
  789.  
  790.     <!-- Documentation for the response of custom methods returning
  791.         and entry or a collection.
  792.     -->
  793.     <xsl:template match="wadl:response/wadl:representation[@href]">
  794.         <xsl:variable name="id" select="substring-after(@href, '#')" />
  795.         <xsl:variable name="resource_type"
  796.             select="substring-before($id, '-')"/>
  797.  
  798.         <p class="response">Response contains an
  799.             <xsl:apply-templates select="key('id', $id)"
  800.                 mode="representation-type"/>
  801.             representation of a
  802.             <a href="#{$resource_type}"><xsl:value-of
  803.                 select="$resource_type"
  804.             /></a><xsl:if test="contains($id, '-page')">
  805.                     collection
  806.                 </xsl:if>.
  807.         </p>
  808.     </xsl:template>
  809.  
  810.     <!-- Documentation for request parameter. -->
  811.     <xsl:template match="wadl:param">
  812.         <tr>
  813.             <xsl:call-template name="param-name"/>
  814.             <td>
  815.                 <xsl:if test="@required or @repeating">
  816.                     <p>
  817.                         <xsl:if test="@required='true'">
  818.                             <small>(required)</small>
  819.                         </xsl:if>
  820.                         <xsl:if test="@repeating='true'">
  821.                             <small>(repeating)</small>
  822.                         </xsl:if>
  823.                     </p>
  824.                 </xsl:if>
  825.                 <xsl:call-template name="param-value"/>
  826.             </td>
  827.             <xsl:call-template name="param-description"/>
  828.         </tr>
  829.     </xsl:template>
  830.  
  831.     <!-- Documentation for factories.
  832.  
  833.     Factory's response include a Location header pointint to a resource type.
  834.     -->
  835.     <xsl:template match="wadl:response/wadl:param[
  836.         @name = 'Location' and @style = 'header'
  837.         and wadl:link[@resource_type]]">
  838.         <xsl:variable name="resource_type"
  839.             select="substring-after(
  840.                 wadl:link[@resource_type]/@resource_type, '#')"/>
  841.         <p>On success, the response status will be 201 and the
  842.             <var>Location</var> header will contain the link to the newly
  843.             created <a href="#{$resource_type}"
  844.                 ><xsl:value-of select="$resource_type" /></a>.
  845.         </p>
  846.     </xsl:template>
  847.  
  848.     <!-- Output the available value for the parameter. -->
  849.     <xsl:template match="wadl:option">
  850.         <li>
  851.             <tt><xsl:value-of select="@value"/></tt>
  852.             <xsl:if test="ancestor::wadl:param[1]/@default=@value">
  853.                 <small>(default)</small>
  854.             </xsl:if>
  855.         </li>
  856.     </xsl:template>
  857.  
  858.     <!-- Ouput list of the documentation for each available option. -->
  859.     <xsl:template match="wadl:option" mode="option-doc">
  860.             <dt>
  861.                 <tt><xsl:value-of select="@value"/></tt>
  862.                 <xsl:if test="ancestor::wadl:param[1]/@default=@value">
  863.                     <small>(default)</small>
  864.                 </xsl:if>
  865.             </dt>
  866.             <dd>
  867.                 <xsl:apply-templates select="wadl:doc"/>
  868.             </dd>
  869.     </xsl:template>
  870.  
  871.     <!-- Format wadl:doc -->
  872.     <xsl:template match="wadl:doc">
  873.         <xsl:param name="inline">0</xsl:param>
  874.         <!-- skip WADL elements -->
  875.         <xsl:choose>
  876.             <xsl:when test="node()[1]=text() and $inline=0">
  877.                 <p>
  878.                     <xsl:apply-templates select="node()" mode="copy"/>
  879.                 </p>
  880.             </xsl:when>
  881.             <xsl:otherwise>
  882.                 <xsl:apply-templates select="node()" mode="copy"/>
  883.             </xsl:otherwise>
  884.         </xsl:choose>
  885.     </xsl:template>
  886.  
  887.     <!-- Returns the title or id of an element.
  888.  
  889.     Look for the first wadl:doc title attribute content of the
  890.     current node or fall back to the element id.
  891.  
  892.     :param element: The element to return the title or id. Defaults to the
  893.         current node.
  894.     -->
  895.     <xsl:template name="get-title-or-id">
  896.         <xsl:param name="element" select="current()" />
  897.         <xsl:choose>
  898.             <xsl:when test="$element/wadl:doc[@title]">
  899.                 <xsl:value-of select="$element/wadl:doc[@title][1]/@title"/>
  900.             </xsl:when>
  901.             <xsl:otherwise>
  902.                 <xsl:value-of select="$element/@id"/>
  903.             </xsl:otherwise>
  904.         </xsl:choose>
  905.     </xsl:template>
  906.  
  907.     <!-- Output the mediaType attribute of the default representation.
  908.  
  909.     Should be call on an element that contain a wadl:representation element
  910.     without a mediaType attribute.
  911.     -->
  912.     <xsl:template name="representation-type">
  913.         <xsl:apply-templates
  914.             select="key('id',
  915.                         substring-after(
  916.                             .//wadl:representation[not(@mediaType)]/@href,
  917.                             '#'))"
  918.              mode="representation-type"/>
  919.     </xsl:template>
  920.  
  921.     <!-- Omit docutils parameter lists in methods since they are redundant
  922.     or misleading with the one we give. -->
  923.     <xsl:template match="wadl:method//html:table[
  924.         contains(@class, 'field-list')]"
  925.         mode="copy"/>
  926.  
  927.     <!-- Output the mediaType attribute of a representation -->
  928.     <xsl:template match="wadl:representation[@mediaType]"
  929.         mode="representation-type">
  930.         <code><xsl:value-of select="@mediaType"/></code>
  931.     </xsl:template>
  932.  
  933.     <!-- Copy html elements. -->
  934.     <xsl:template match="html:*" mode="copy">
  935.         <!-- remove the prefix on HTML elements -->
  936.         <xsl:element name="{local-name()}">
  937.             <xsl:for-each select="@*">
  938.                 <xsl:attribute name="{local-name()}"
  939.                     ><xsl:value-of select="."/></xsl:attribute>
  940.             </xsl:for-each>
  941.             <xsl:apply-templates select="node()" mode="copy"/>
  942.         </xsl:element>
  943.     </xsl:template>
  944.  
  945.     <xsl:template match="@*|node()[
  946.             namespace-uri()!='http://www.w3.org/1999/xhtml']" mode="copy">
  947.         <!-- everything else goes straight through -->
  948.         <xsl:copy>
  949.             <xsl:apply-templates select="@*|node()" mode="copy"/>
  950.         </xsl:copy>
  951.     </xsl:template>
  952.  
  953. </xsl:stylesheet>
  954.